package com.atguigu.utils;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"离开了教室");
                latch.countDown();
            },String.valueOf(i)).start();
        }
        //线程每执行一次值减一,减到0的时候主线程唤醒执行锁门,不到0没有线程可以执行
        latch.await();
        System.out.println(Thread.currentThread().getName()+"锁门");
    }
}

